require 'rubygems'
require 'active_record'
require 'blog'

class CreateTables < ActiveRecord::Migration
  def self.up
    create_table :sites do |t|
      t.string :name
      t.string :url
      t.integer :blogid
      t.string :username
      t.string :passwd
    end
    
    create_table :media do |t|
      t.string :name
      t.string :type
    end
    
    create_table :mpublications do |t|
      t.integer :site_id
      t.integer :media_id
      t.string :murl
    end
    
    create_table :articles do |t|
      t.string :title
      t.text :content
      t.datetime :created_at
    end
    
    create_table :publications do |t|
      t.integer :site_id
      t.integer :article_id
      t.datetime :published_at
    end
  end
  
  def self.down
    drop_table :sites
    drop_table :media
    drop_table :mpublications
    drop_table :articles
    drop_table :publications
  end
end

class AddCustom < ActiveRecord::Migration
  def self.up
    add_column :articles, :custom, :text
  end
  
  def self.down
    remove_column :articles, :custom
  end
end

class CreateCategories < ActiveRecord::Migration
  def self.up
    create_table :categories do |t|
      t.string :name
      t.integer :site_id
    end
  end
  
  def self.down
    drop_table :categories
  end
end

class AddType < ActiveRecord::Migration
  # add type field to site
  def self.up
    add_column :sites, :type, :string
  end
  
  def self.down
    remove_column :sites, :type
  end
end

class AddLastModified < ActiveRecord::Migration
  def self.up
    add_column :articles, :modified_at, :datetime
  end
  
  def self.down
    remove_column :articles, :modified_at
  end
end

class AddTagsPubId < ActiveRecord::Migration
  def self.up
    add_column :articles, :tags, :string
    add_column :publications, :pub_id, :string
  end
  
  def self.down
    remove_column :articles, :tags
    remove_column :publications, :pub_id
  end
end

class CreateArticleCategories < ActiveRecord::Migration
  def self.up
    create_table :article_categories do |t|
      t.integer :article_id
      t.string :name
    end
  end
  
  def self.down
    drop_table :article_categories
  end
end
